﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TowerDefence.Entities.States;
using TowerDefence.Entities.Actions;
using Action = TowerDefence.Entities.Actions.Action;
using Microsoft.Xna.Framework;

namespace TowerDefence.Entities
{
    public interface IEntity
    {
        void AddAction(Action _action);
        void RemoveAction(Action _action);
        void Update(TimeSpan _time);
        Form Form { get; set; }
        StateContainer States { get; set; }
    }

    /// <summary>
    /// The class for all game entities.
    /// This is a collection of Action and State objects which
    /// provide the actual functionality of the entity.
    /// </summary>
    public class Entity
    {        
        StateContainer states;
        List<Action> actions;

        public Form Form { get; set; }
        public StateContainer States { get; private set; }

        public Entity()
        {
            States = new StateContainer();
            this.actions = new List<Action>();
        }

        public void AddAction(Action _action)
        {
            this.actions.Add(_action);
        }

        public void RemoveAction(Action _action)
        {
            this.actions.Remove(_action);
        }

        public void Update(TimeSpan _time)
        {
            // TODO: remove inactive actions
            foreach(var action in this.actions)
            {
                action.DoAction(_time);
            }
        }
    }
}
